home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / MacTutor Help Source / Code Resource Version / C Example / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-26  |  4.2 KB  |  140 lines  |  [TEXT/KAHL]

  1. /***********************************************************************\
  2. | Purpose :: This module is responsible for initializing the program    |
  3. |             and entering the main event loop.                            |
  4. |-----------------------------------------------------------------------|
  5. |        Copyright © Joe Pillera, 1990.  All Rights Reserved.            |
  6. \***********************************************************************/
  7.  
  8. #include "demo.h"
  9.  
  10. /***********************************************************************\
  11. |                           void  main( void )                                |
  12. |-----------------------------------------------------------------------|
  13. | Purpose :: To peform the routine initializations and enter the demo    |
  14. |             program's event loop.                                        |
  15. |-----------------------------------------------------------------------|
  16. | Arguments ::    None.                                                    |
  17. |-----------------------------------------------------------------------|
  18. | Returns :: Exits to Finder.                                            |
  19. \***********************************************************************/
  20.  
  21. Boolean        program_done;
  22.  
  23. void main()
  24. {
  25.     /* Perform routine initializations */
  26.     MoreMasters ();
  27.     MoreMasters ();
  28.     MoreMasters ();
  29.     FlushEvents (-1, 0);
  30.     InitGraf (&thePort);
  31.     InitFonts ();
  32.     InitWindows ();
  33.     TEInit ();
  34.     InitMenus ();
  35.     InitDialogs (NIL);
  36.     InitCursor ();
  37.  
  38.     /* Load in the menu bar */
  39.     ClearMenuBar();                     
  40.     SetMenuBar (GetNewMBar (MBarID));
  41.     AddResMenu (GetMHandle (AppleID), 'DRVR');
  42.     DrawMenuBar ();
  43.     
  44.     /* Enter the main event loop until done */
  45.     program_done = FALSE;
  46.     Do_Event_Loop();
  47. }
  48.  
  49.  
  50.  
  51.  
  52. /***********************************************************************\
  53. |                         void  Do_Event_Loop( void )                        |
  54. |-----------------------------------------------------------------------|
  55. | Purpose :: To implement the main event loop.                          |
  56. |-----------------------------------------------------------------------|
  57. | Arguments ::    None.                                                    |
  58. |-----------------------------------------------------------------------|
  59. | Returns :: void                                                        |
  60. \***********************************************************************/
  61.  
  62. void Do_Event_Loop()
  63. {
  64.     char              ch;                   /* Key pressed in Ascii                 */
  65.     short            code;                  /* Determine event type                 */
  66.     short            theMenu,theItem;       /* Menu list and item selected             */
  67.     short            chCode;                /* Key code                             */
  68.     long             mResult;               /* Menu list and item selected values    */
  69.     WindowPtr       whichWindow;           /* See which window for event             */
  70.     EventRecord      myEvent;               /* Event record for all events             */
  71.     TEHandle         theInput;              /* Used in text edit selections         */
  72.     GrafPtr           SavePort;             /* Place to save current drawing port     */ 
  73.  
  74.     do {                                
  75.     SystemTask();                       
  76.      if (GetNextEvent(everyEvent, &myEvent))    {
  77.         code = FindWindow(myEvent.where, &whichWindow);    
  78.           
  79.         switch (myEvent.what)  {         
  80.             case mouseDown:             
  81.                 if (code == inMenuBar) {
  82.                     mResult = MenuSelect(myEvent.where);
  83.                     Do_Command(mResult);
  84.                     }
  85.  
  86.                 if (code == inContent) {
  87.                     if (whichWindow != FrontWindow()) 
  88.                         SelectWindow(whichWindow);
  89.                     else                
  90.                         SetPort(whichWindow);
  91.                     }                   
  92.  
  93.                 if (code == inSysWindow)
  94.                     SystemClick(&myEvent, whichWindow);
  95.                 break;                  
  96.  
  97.             case keyDown:               
  98.             case autoKey:               
  99.                 ch = myEvent.message &  charCodeMask;
  100.                 if (myEvent.modifiers & cmdKey) {
  101.                     mResult = MenuKey(ch);
  102.                     theMenu = HiWord(mResult);
  103.                     if (theMenu == FileID)
  104.                       Do_Command(mResult);
  105.                 }
  106.                 break;                  
  107.  
  108.             case updateEvt:             
  109.                 whichWindow = (WindowPtr)myEvent.message;
  110.                 GetPort(&SavePort);
  111.                 BeginUpdate(whichWindow);
  112.                 SetPort(whichWindow);
  113.                 EndUpdate(whichWindow);
  114.                 SetPort(SavePort);      
  115.                 break;                  
  116.  
  117.             case diskEvt:               
  118.                 if (HiWord(myEvent.message) != 0)  {
  119.                     myEvent.where.h = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - (304 / 2);
  120.                     myEvent.where.v = ((screenBits.bounds.bottom - screenBits.bounds.top) / 3) - (104 / 2);
  121.                     InitCursor();       
  122.                     theItem = DIBadMount(myEvent.where, myEvent.message);
  123.                     }                   
  124.                 break;                  
  125.  
  126.             case activateEvt:           
  127.                 if ((whichWindow != NIL) && (myEvent.modifiers & activeFlag))
  128.                     SelectWindow(whichWindow);
  129.                 break;                  
  130.  
  131.  
  132.             default:                    
  133.                 break;                  
  134.  
  135.         }                               
  136.        }                               
  137.     }                                   
  138.     while (program_done ==  FALSE);             
  139. }                                       
  140.